/**
 * https://leetcode-cn.com/problems/pascals-triangle-ii/
 * 给定某行索引, 返回杨辉三角改行的值
 * @param rowIndex 
 */
const getRow = (rowIndex: number): number[] => {
    let curr = [1]
    for (let i = 1; i <= rowIndex; i++) {
        // 获取前一个
        // 当前行
        const row = [1]

        // 给中间赋值
        for (let j = 1; j < i; j++) {
            row.push(curr[j - 1] + curr[j])
        }

        row.push(1)
        curr = row
    }

    return curr;
};


const getRow2 = (rowIndex: number): number[] => {
    const arr: number[][] = [[1]]
    for (let i = 1; i <= rowIndex; i++) {
        // 获取前一个
        const prev = arr[i - 1];

        // 当前行
        const row = [1]

        // 给中间赋值
        for (let j = 1; j < i; j++) {
            row.push(prev[j - 1] + prev[j])
        }

        row.push(1)

    }

    return arr[arr.length - 1]
};